package com.goodving.guli.server;

import android.os.SystemClock;

import com.goodving.guli.bt.dataprocess.HeartRateInfo;
import com.goodving.guli.bt.model.SportBaseInfo;
import com.goodving.guli.utility.Constants;
import com.goodving.guli.view.C3657a;
import com.goodving.guli.view.C4220a;
import com.loopj.android.http.AsyncHttpResponseHandler;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.security.MessageDigest;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Random;
import java.util.regex.Pattern;

import cn.com.smartdevices.bracelet.config.Config;


/* renamed from: cn.com.smartdevices.bracelet.j.h */
public class ClientUtil { // C1325h
    private static String f6799a;

    static {
        f6799a = "^(([\\w-]+\\.)+[\\w-]+|([a-zA-Z]{1}|[\\w-]{2,}))@((([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\\.([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\\.([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\\.([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])){1}|([a-zA-Z]+[\\w-]+\\.)+[a-zA-Z]{2,4})$";
    }

    public static long m11566a() {
        return new Date().getTime();
    }

    public static String m11567a(String str) {
        int nextInt = new Random(SystemClock.currentThreadTimeMillis()).nextInt(90) + 10;
        return ClientUtil.m11571b(nextInt + str) + C4220a.ci + nextInt;
    }

    public static String m11568a(HashMap<String, String> hashMap) {
        StringBuffer stringBuffer = new StringBuffer();
        List<String> arrayList = new ArrayList();
        Config h = Config.m8876h();
        for (HashMap.Entry<String, String> key : hashMap.entrySet()) {
            arrayList.add(key.getKey());
        }
        Collections.sort(arrayList, String.CASE_INSENSITIVE_ORDER);
        for (String str : arrayList) {
            stringBuffer.append((String) hashMap.get(str));
        }
        h.getClass();
        stringBuffer.append("c18c24046606b2e084edd37f9fe9f94d");
        return ClientUtil.m11571b(stringBuffer.toString());
    }

    public static HashMap<String, String> m11569a(Map<String, String> map) {
        HashMap hashMap = new HashMap();
        Config h = Config.m8876h();
        String c = ClientUtil.m11573c("appid");
        h.getClass();
        hashMap.put(c, ClientUtil.m11573c("1uMqYWpHo3MoLH"));
        hashMap.put(ClientUtil.m11573c(ClientDataConstants.PARAM_CALLID), ClientUtil.m11573c(C3657a.f18328f + ClientUtil.m11566a()));
        c = ClientUtil.m11573c(SportBaseInfo.VERSION);
        h.getClass();
        hashMap.put(c, ClientUtil.m11573c("1.0"));
        hashMap.put(ClientUtil.m11573c(ClientDataConstants.PARAM_SYS_LANGUAGE), ClientUtil.m11573c(Locale.getDefault().getLanguage()));
        if (map != null) {
            hashMap.putAll(map);
        }
        hashMap.put(ClientDataConstants.f6737h, ClientUtil.m11568a(hashMap));
        return hashMap;
    }

    public static boolean m11570a(String str, String str2) {
        return str != null && str.length() >= 1 && str2 != null && str2.length() >= 6 && str2.length() <= 25 && Pattern.compile(f6799a).matcher(str).matches();
    }

    public static String m11571b(String str) {
        try {
            byte[] digest = MessageDigest.getInstance("MD5").digest(str.getBytes(AsyncHttpResponseHandler.DEFAULT_CHARSET));
            StringBuilder stringBuilder = new StringBuilder(digest.length * 2);
            for (byte b : digest) {
                if ((b & HeartRateInfo.HR_EMPTY_VALUE) < 16) {
                    stringBuilder.append(Constants.VIA_RESULT_SUCCESS);
                }
                stringBuilder.append(Integer.toHexString(b & HeartRateInfo.HR_EMPTY_VALUE));
            }
            return stringBuilder.toString();
        } catch (Throwable e) {
            throw new RuntimeException("Huh, MD5 should be supported?", e);
        }
    }

    public static HashMap<String, String> m11572b(Map<String, String> map) {
        HashMap<String, String> hashMap = new HashMap();
        HashMap hashMap2 = new HashMap();
        Config h = Config.m8876h();
        String c = ClientUtil.m11573c("appid");
        h.getClass();
        hashMap.put(c, ClientUtil.m11573c("1uMqYWpHo3MoLH"));
        hashMap.put(ClientUtil.m11573c(ClientDataConstants.PARAM_CALLID), ClientUtil.m11573c(C3657a.f18328f + ClientUtil.m11566a()));
        c = ClientUtil.m11573c(SportBaseInfo.VERSION);
        h.getClass();
        hashMap.put(c, ClientUtil.m11573c("1.0"));
        hashMap.put(ClientUtil.m11573c(ClientDataConstants.PARAM_SYS_LANGUAGE), ClientUtil.m11573c(Locale.getDefault().getLanguage()));
        hashMap2.putAll(hashMap);
        if (map != null) {
            hashMap2.putAll(map);
        }
        hashMap.put(ClientDataConstants.f6737h, ClientUtil.m11568a(hashMap2));
        return hashMap;
    }

    public static String m11573c(String str) {
        String str2 = null;
        try {
            str2 = URLEncoder.encode(str, AsyncHttpResponseHandler.DEFAULT_CHARSET);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (Exception e2) {
            e2.printStackTrace();
        }
        return str2;
    }
}
